/**
 * 党组织党员数量分析
 */
import dzzIcon1 from "../../assets/dp2/dzz-icon1.png";
import dzzIcon2 from "../../assets/dp2/dzz-icon2.png";
import dzzIcon3 from "../../assets/dp2/dzz-icon3.png";
import dzzIcon4 from "../../assets/dp2/dzz-icon4.png";
import dzzIcon5 from "../../assets/dp2/dzz-icon5.png";
import dzzIcon6 from "../../assets/dp2/dzz-icon6.png";
import dzzIcon7 from "../../assets/dp2/dzz-icon7.png";


export const dzzfx1Render = (params = {},chart1) => {
    console.log(chart1,"ccccc")
    var Shape = G2.Shape;
    Shape.registerShape("point", "image", {
        drawShape: function drawShape(cfg, container) {
            cfg.points = this.parsePoints(cfg.points);
            var coord = this._coord;
            container.addShape("line", {
                attrs: {
                    x1: cfg.points[0].x,
                    y1: cfg.points[0].y,
                    x2: cfg.points[0].x,
                    y2: coord.start.y,
                    stroke: "#ccc",
                    lineWidth: 1,
                    lineDash: [4, 2]
                }
            });
            return container.addShape("image", {
                attrs: {
                    x: cfg.points[0].x - 12 * cfg.size / 2,
                    y: cfg.points[0].y - 12 * cfg.size,
                    width: 12 * cfg.size,
                    height: 12 * cfg.size,
                    img: cfg.shape[1]
                }
            });
        }
    });
    var defaultData = [
        {
            name: "乡镇",
            value: 0
        },
        {
            name: "事业单位",
            value: 0
        },
        {
            name: "建制村",
            value: 0
        },
        {
            name: "国有经济控制",
            value: 0
        },
        {
            name: "机关",
            value: 0
        },
        {
            name: "非公有经济控制",
            value: 0
        },
        {
            name: "社会组织",
            value: 0
        }
    ];
    let {data = [],max} = params;
    let dataSource = data.length?data:defaultData;
    var imageMap = {
        乡镇: dzzIcon1,
        事业单位: dzzIcon2,
        建制村: dzzIcon3,
        国有经济控制: dzzIcon4,
        机关: dzzIcon5,
        非公有经济控制: dzzIcon6,
        社会组织: dzzIcon7
    };
    if(!chart1){
        chart1 = new G2.Chart({
            container: "dzzfx1",
            forceFit: true,
            height: 250,
            padding: [20, 0, 60, 40]
        });
    }
    // var chart = new G2.Chart({
    //     container: "dzzfx1",
    //     forceFit: true,
    //     height: 250,
    //     padding: [20, 0, 60, 40]
    // });
    chart1.legend("gender", {
        title: {
            fill: "#fff"
        }
    });
    chart1.source(dataSource, {
        value: {
            nice: true,
            max,
            min: 0
        }
    });
    chart1.legend(false);
    chart1.axis("value", false);
    chart1.axis("name", {
        label: {
            textStyle: {
                fill: "#ffd2d2",
                textAlign: "right"
            },
            offsetY: -5,
            rotate: -20,
            autoRotate: false
        }
    });
    chart1
        .point()
        .position("name*value")
        .size("2.5")
        .shape("name", function (name) {
            return ["image", imageMap[name]]; // 根据具体的字段指定 shape
        })
        .label("value", {
            offset: -10,
            textStyle: {
                fontSize: 16, // 文本大小
                fill: "#ffd2d2"
            }
        });
    chart1.render();
    return chart1;
}

/**
 * 党员年龄性别分析
 */
// export let xbfxRender = ()=>{
//     let options = {
//         tooltip: {
//             show: false,
//             // trigger: 'axis',
//             // axisPointer : {            // 坐标轴指示器，坐标轴触发有效
//             //     type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
//             // },
//             // formatter: function (params, ticket, callback) {
//             //     console.log(params,ticket,callback)
//             //     var res = params[0].name ;
//             //     for (var i = 0, l = params.length; i < l; i++) {
//             //         res += '<br/>' + params[i].seriesName + ' : ' + Math.abs(params[i].value) ;     
//             //         }
//             //     setTimeout(function () {
//             //         // 仅为了模拟异步回调
//             //     callback(ticket, res);
//             //     }, 0)
//             //     return ' ';
//             // }
//         },
//         color: ["#74c7ed","#d68aac"],
//         legend: false,
//         grid: {
//             left: '3%',
//             right: '4%',
//             bottom: 0,
//             top:0,
//             containLabel: true
//         },
//         xAxis: [
//             {
//                 type: 'value',
//                 splitLine: { show: false },
//                 axisLabel: {
//                     color: "#3c3c43"
//                 },
//                 axisLine: {
//                     show: false,
//                     lineStyle: {
//                         color: "#3c3c43"
//                     }
//                 },
//                 axisLabel: {
//                     show:false,
//                     color: "#fff",
//                 },

//             }

//         ],
//         yAxis: [
//             {
//                 type: 'category',
//                 axisTick: { show: false },
//                 data: ["20以下", "20到40", "40到60", "60到80", "80以上"],
//                 axisLine: {
//                     show: false,
//                 },
//                 splitLine: { show: false },
//                 axisLabel: {
//                     show:false,
//                     align:"right",
//                     position:"bottom",
//                     color: "#fff"
//                 }
//             }
//         ],
//         series: [
//             {
//                 name: '男',
//                 type: 'bar',
//                 stack: '总量',
//                 label: {
//                     normal: {
//                         show: true,
//                         position: "left",
//                         color: "#fff",
//                         formatter: function (v) { return Math.abs(v.data) }
//                     }
//                 },
//                 data: [-120, -1567, -678, -256, -298]
//             },
//             {
//                 name: '女',
//                 type: 'bar',
//                 stack: '总量',
//                 label: {
//                     normal: {
//                         show: true,
//                         position: "right",
//                         color: "#fff",
//                         formatter: function (v) { return Math.abs(v.data) }
//                     }
//                 },
//                 data: [76, 1125, 356, 223, 212]
//             },
//         ]
//     };
//     return options;
// };

export const xbfxRender = (params = {},chart2) => {
    var defaultData = [
        {
            label: '20以下',
            type: '男',
            value: 0
        }, {
            label: '20以下',
            type: '女',
            value: 0
        }, {
            label: '20到40',
            type: '男',
            value: 0
        }, {
            label: '20到40',
            type: '女',
            value: 0
        }, {
            label: '40到60',
            type: '男',
            value: 0
        }, {
            label: '40到60',
            type: '女',
            value: 0
        }, {
            label: '60到80',
            type: '男',
            value: 0
        }, {
            label: '60到80',
            type: '女',
            value: 0
        }, {
            label: '80以上',
            type: '男',
            value: 0
        }, {
            label: '80以上',
            type: '女',
            value: 0
        },
    ];
    if(!chart2){
        chart2 = new G2.Chart({
            container: 'xbfx',
            forceFit: true,
            height: 138,
            padding: [0, 0, 0, 0],
        });
    }
    let {data = []} = params;
    let dataSource = data.length?data:defaultData;
    chart2.source(dataSource, {
        value: {
            nice: true,
            alias: '年龄性别统计',
        }
    });
    chart2.axis('value', false);
    chart2.coord().transpose();
    chart2.facet('mirror', {
        fields: ['type'],
        transpose: true,
        showTitle: false,
        padding: [0, 40, 0, 20],
        eachView: function eachView(view, facet) {
            var facetIndex = facet.colIndex;
            if (facetIndex === 0) {
                view.axis('label', {
                    position: 'right',
                    grid: null,
                    label: {
                        textStyle: {
                            fill: '#fff',
                            fontSize: 12
                        },
                    },
                    tickLine: {
                        alignWithLabel: false,
                        length: 0
                    },
                    line: {
                        lineWidth: 0
                    }
                });
            } else {
                view.axis('label', false);
            }
            var color = facetIndex === 0 ? '#74c7ed' : '#d68aac';
            view.interval().position('label*value').color(color).size(18).opacity(1).label('value', function (val,arg) {
                var offset = -4;
                var shadowBlur = 2;
                var textAlign = facetIndex === 1 ? 'start' : 'end';
                var fill = '#333';
                // if (val < 15) {
                //     offset = 4;
                //     textAlign = facetIndex === 1 ? 'start' : 'end';
                //     fill = '#666666';
                //     shadowBlur = 0;
                // }
                return {
                    //position: 'middle',
                    offset: 0,
                    textStyle: {
                        fill: "#fff",
                        shadowBlur: shadowBlur,
                        shadowColor: 'rgba(0, 0, 0, .45)',
                        textAlign
                    }
                };
            });
        }
    });
    chart2.render();
    return chart2;
}


/**
 * 学习情况分析
 */
export const xxqkOption = () => {
    let option = {
        tooltip: {
            trigger: "axis",
            axisPointer: {
                // 坐标轴指示器，坐标轴触发有效
                type: "shadow" // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        color: ["#34a1e1", "#d92016","#589fa9"],
        legend: {
            data: [
                "学习强国",
                "三会一课",
                "不忘初心牢记使命",
            ],
            textStyle: {
                color: "#fff"
            }
        },
        grid: {
            left: "0%",
            right: "0%",
            bottom: "0%",
            top: "30",
            containLabel: true
        },
        xAxis: {
            type: "category",
            axisLabel: {
                rotate: 20,
                color: "#fff"
            },
            axisLine: {
                lineStyle: {
                    color: "#fff",
                }
            },

            data: [
                "机关",
                "乡镇",
                "事业单位",
                "其他",
                "国有经济控制",
                "建制村",
                "非公有经济控制",
                "社会组织",
            ]
        },
        yAxis: {
            type: "value",
            // axisLine: {
            //     show: false,
            //     lineStyle: {
            //         // color:"#fff"
            //     }
            // },
            splitLine: {
                lineStyle: {
                    color: "#959595",
                    type: "dashed"
                }
            },
            axisLabel: {
                color: "#fff"
            }
        },
        series: [
            {
                name: "三会一课",
                type: "bar",
                stack: "总量",
                barWidth: 40,
                label: {
                    normal: {
                        show: true,
                    }
                },
                data: [213, 17, 209, 41, 68, 515, 184,30]
            },
            {
                name: "学习强国",
                type: "bar",
                stack: "总量",
                barWidth: 40,
                label: {
                    normal: {
                        show: true,
                    }
                },
                data: [983, 0, 0, 0, 0, 0, 0,0]
            },
            {
                name: "不忘初心牢记使命",
                type: "bar",
                stack: "总量",
                barWidth: 40,
                label: {
                    normal: {
                        show: true,
                    }
                },
                data: [296, 35, 265, 48, 105, 486, 157,22]
            },

        ]
    };
    return option;
}

/**
 * 组织活动类型分析
 */
export const hdlxOption = () => {
    let option = {
        // grid: {
        //     top: "3%",
        //     right: "4%",
        //     bottom: "3%",
        //     containLabel: true
        // },
        tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        color: ["#db2218", "#43818b", "#e5855e", "#68b997", "#e94c00"],
        legend: {
            orient: 'vertical',
            right: 10,
            top: 50,
            bottom: 20,
            data: ['扶贫解困', '先进学习', '培训讲座', "网页学习", "知识竞赛"],
            textStyle: {
                color: "#fff",
            }
        },
        calculable: true,
        series: [
            {
                name: '组织活动类型分析',
                type: 'pie',
                hoverAnimation: false,
                radius: [30, 98],
                center: ['42%', '55%'],
                roseType: 'radius',
                label: {
                    normal: {
                        position: 'inner',
                        formatter: "{c} {d}%"
                    }
                },
                lableLine: {
                    normal: {
                        show: true
                    },
                    // emphasis: {
                    //     show: true
                    // }
                },
                data: [
                    { value: 2, name: '扶贫解困' },
                    { value: 52, name: '先进学习' },
                    { value: 3, name: '培训讲座' },
                    { value: 63, name: '网页学习' },
                    { value: 2, name: '知识竞赛' },
                ]
            }
        ]
    };
    return option;
}

